//
//  SynchronizationObject.h
//
//  Created by Alexander Chaika on 24.01.12.
//  Copyright 2012 by Alexander Chaika. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <SBJson/SBJson.h>

@interface Synchronization : NSObject {
	NSTimer *checkTimer; // timer
	NSString *accessToken; // result access token
	NSDate *accessTokenExpires; // when access token will expire

	int operationInProgress; // pending operation type
	
	NSURLConnection *curConnection; // current connection
	NSMutableData *receivedData; // url loading helper
	
	SBJsonParser *parser; // parser
	
	int contactsState; // current state of contacts sync operation
	NSDate *contactsNextSync; // when to sync contacts
	
	int calendarsState; // current state of calendars sync operation
	NSDate *calendarsNextSync; // when to sync calendars
}

- (IBAction)synchronizeNow:(id)sender; // action to force synchronization
- (IBAction)syncContactsNow:(id)sender; // action to force contacts synchronization
- (IBAction)syncCalendarsNow:(id)sender; // action to force calendars synchronization
- (IBAction)updateSyncSchedule:(id)sender; // update next time sync
- (IBAction)updateContactsSyncSchedule:(id)sender; // update next time sync for contacts
- (IBAction)updateCalendarsSyncSchedule:(id)sender; // update next time sync for calendars

- (void)start; // start sync
- (void)stop; // stop sync
- (void)restart; // restart sync

@property (retain) NSString *accessToken;
@property (retain) NSDate *accessTokenExpires;
@property (retain) NSDate *contactsNextSync;
@property (retain) NSDate *calendarsNextSync;

@end
